function toChanese(num) {
  switch (num) {
    case 1:
      return "一";
    case 2:
      return "二";
    case 3:
      return "三";
    case 4:
      return "四";
    case 5:
      return "五";
    case 6:
      return "六";
    case 0:
      return "日";
    default:
      break;
  }
}
Date.prototype.format = function (fmt) {
  let o = {
    "M+": this.getMonth() + 1, // 月份
    "d+": this.getDate(), // 日
    "h+": this.getHours(), // 小时
    "m+": this.getMinutes(), // 分
    "s+": this.getSeconds(), // 秒
    "q+": Math.floor((this.getMonth() + 3) / 3), // 季度
    S: this.getMilliseconds(), // 毫秒
    几: toChanese(this.getDay()),
  };

  if ((/(y+)/).test(fmt)) {
    fmt = fmt.replace(
      RegExp.$1,
      (this.getFullYear() + "").substr(4 - RegExp.$1.length)
    );
  }

  for (let k in o) {
    if (new RegExp("(" + k + ")").test(fmt)) {
      fmt = fmt.replace(
        RegExp.$1,
        RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)
      );
    }
  }

  return fmt;
};
Date.prototype.sayHello = function (name = "") {
  let nowHours = this.getHours();
  if (3 <= nowHours && nowHours < 6) {
    return `凌晨了，${name ? name + "，" : ""}勤奋的你早点休息吧！`;
  } else if (6 <= nowHours && nowHours < 8) {
    return `早上好，${name ? name + "，" : ""}今天又是元气满满的一天！`;
  } else if (8 <= nowHours && nowHours < 11) {
    return `上午好，${name ? name + "，" : ""}一天之计在于晨!`;
  } else if (11 <= nowHours && nowHours < 13) {
    return `中午好，${name ? name + "，" : ""}干饭人干饭魂干饭不要停！`;
  } else if (13 <= nowHours && nowHours < 17) {
    return `下午好，${name}`;
  } else if (17 <= nowHours && nowHours < 23) {
    return `晚上好，${name ? name + "，" : ""}还在加班的你，是全公司最靓的崽！`;
  } else {
    return `夜深了，${name ? name + "，" : ""}勤奋的你早点休息吧！`;
  }
};
Date.prototype.interval = function () {
  let nowHours = this.getHours();
  if (3 <= nowHours && nowHours < 6) {
    return "凌晨了，";
  } else if (6 <= nowHours && nowHours < 8) {
    return "早上好，";
  } else if (8 <= nowHours && nowHours < 11) {
    return "上午好，";
  } else if (11 <= nowHours && nowHours < 13) {
    return "中午好，";
  } else if (13 <= nowHours && nowHours < 17) {
    return `下午好，${name}`;
  } else if (17 <= nowHours && nowHours < 23) {
    return "晚上好，";
  } else {
    return "夜深了，";
  }
};
Date.prototype.compare = function (date) {
  return this > date;
};
